var express = require('express');
var router   = express.Router();
var dataCtrl = require('../controllers/user.controllers');
function verifyToken(req,res,next){
	console.log(req.headers['authorization']);
	const beaerHeader =req.headers['authorization'];
	if(typeof beaerHeader !=='undefined'){
		const bearer =beaerHeader.split(' ');
		const bearerToken=bearer[1];
		req.token=bearerToken;
		next();
	}else{
		res.sendStatus(403);
	}
}

/* GET users listing. */
router.get('/', function(req, res, next) {
  res.send('respond with a resource');
});


router.post('/data', dataCtrl.create);
router.put('/data/:id', dataCtrl.update);
router.delete('/data/:id', dataCtrl.remove);
router.post('/list',verifyToken, dataCtrl.list);
router.get('/data/:id', dataCtrl.getData);
router.post('/data/removes', dataCtrl.removes);
router.post('/login', dataCtrl.login);


module.exports = router;  //44
